import $axios from "@/common/http.js";//请求实例
import { Message } from "element-ui";
import router from "@/router"
import store from "@/store";


/**
 * 登录
 * @param {*} data 
 * @returns 
 */
export const userLogin = async (data) => {
    // console.log(data);
    let rst = await $axios.post('/userlogin', { ...data })
    // return rst
    if (rst.code == 200) {
        Message({
            type: "success",
            message: rst.msg,
            duration: 500,
            onClose() {//关闭之后，回到页面

                //存vuex
                store.commit("USERNAME", rst.list.username)
                store.commit("MENUS", rst.list.menus)
                store.commit("MENUSURL", rst.list.menus_url)
                store.commit("SETLIST", rst.list)
                // console.log(store);
                //存本地  数据持久化
                localStorage.setItem('userinof', JSON.stringify(rst.list))
                router.push('/');//跳转页面
            }
        })
        console.log(rst);
    }
}